/*
 * FarmEvent.cpp
 *
 *  Created on: 2013-1-22
 *      Author: heqiu
 */

#include "Global.h"

void FarmEvent::handleEvents(SDL_Event &stEvent) {
	//printf("event:%d x=%d y=%d\n", stEvent.type, stEvent.motion.x,stEvent.motion.y);
	g_GlobalData.g_FarmScreen.m_lock.lock();
	if (g_GlobalData.g_FarmScreen.m_bAlive) {
		if (stEvent.type == SDL_MOUSEMOTION) {
			g_GlobalData.g_FarmScreen.mouseMoving(stEvent.motion.x,
					stEvent.motion.y);
		} else if (stEvent.type == SDL_MOUSEBUTTONDOWN) {
			g_GlobalData.g_FarmScreen.mouseDown(stEvent.motion.x,
					stEvent.motion.y);
		} else if (stEvent.type == SDL_MOUSEBUTTONUP) {
			g_GlobalData.g_FarmScreen.mouseUp(stEvent.motion.x,
					stEvent.motion.y);
		}
	}
	if (g_GlobalData.g_FarmControl.m_bAlive) {
		if (stEvent.type == SDL_MOUSEBUTTONDOWN) {
			g_GlobalData.g_FarmControl.mouseDown(stEvent.motion.x,
					stEvent.motion.y);
		} else if (stEvent.type == SDL_MOUSEBUTTONUP) {
			g_GlobalData.g_FarmControl.mouseUp(stEvent.motion.x,
					stEvent.motion.y);
		}
	}
	g_GlobalData.g_FarmScreen.m_lock.unlock();
}
